package com.yztc.wl.zhibo.totalfragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yztc.wl.zhibo.R;
import com.yztc.wl.zhibo.adapter.OnePagerAdapter;
import com.yztc.wl.zhibo.twoclassfragent.MyFragment;
import com.yztc.wl.zhibo.twoclassfragent.NowFragment;
import com.yztc.wl.zhibo.twoclassfragent.WholeFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wlpc on 2016/11/4.
 */
public class TwoFragment extends Fragment {

    private TabLayout tabs;
    private ViewPager viewPager;
    private List<String> tabNames;
    private List<Fragment> fragments;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_two,container,false);
        viewPager= (ViewPager) view.findViewById(R.id.two_viewpager);
        tabs= (TabLayout) view.findViewById(R.id.two_tablayout);
        tabNames = new ArrayList<>();
        fragments = new ArrayList<>();

        tabNames.add("现在直播");
        tabNames.add("我的关注");
        tabNames.add("全部课程");

        MyFragment myFragment = new MyFragment();
        NowFragment nowFragment = new NowFragment();
        WholeFragment wholeFragment = new WholeFragment();
        fragments.add(nowFragment);
        fragments.add(myFragment);
        fragments.add(wholeFragment);

        OnePagerAdapter onePagerAdapter = new OnePagerAdapter(getFragmentManager(),fragments,tabNames);
        viewPager.setAdapter(onePagerAdapter);
        tabs.setupWithViewPager(viewPager);
        return view;
    }
}
